{include  file="./public/common/top.html"/}

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript"
	src="__ROOT__/public/static/js/jquery-1.4.2.js"></script>
	<script type="text/javascript">
	$(function(){
		sum(); //计算购物车某个商品的金额
		total();//计算购物车总金额
		chk();//
	});
	
	function sum(){
		$('#goods tr').each(function(){
			var price = parseFloat($(this).find("td:eq(4)").text());
			var num	= parseInt($(this).find("input[name='num']").val());
			$(this).find("td:eq(6)").text(price * num);
		})
	}
	function total(){
		var s=0;
		$('#goods tr').each(function(){
			if($(this).find("input[type='checkbox']").attr('checked')){
				var prices = parseFloat($(this).find("td:eq(6)").text());
				s+=prices;
			}		
		})
		$("#total").text(s);
	}
	function change(btn,o){
	    var num = 0;
	    num = $('#'+o).val();
	    var flag=0;
	    for(var i=0;i<num.length;i++)
			if((num.charCodeAt(i)>57 || num.charCodeAt(i)<48) && num.charAt(i)!=32)
			{
				flag=1;
				break;
			}
		if(flag==1)
		{
			alert("数量只能是数字！");
			return false;
		}
		else{
			var tds=$(btn).parent().siblings();
			var yourprice = tds.eq(4).text();	
			tds.eq(5).text(yourprice * num);	
			total();	
	        $.get("{:url('cart/updateCart')}",{"cartID":o,"num":num});
		}
	} 

	function del(btn,cid){
		$(btn).parent().parent().remove();
		total();
		$.get("{:url('cart/deleteCart')}",{"cartID":cid});
	}

	function chk(){
		total();
	}
	</script>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<center>
<img src="__ROOT__/public/static/images/cartbg1.jpg"><br/><br/>
<form action="{:url('order/order')}" name="form1" method="post">
	<table style="width:881px;border-width:1px; border-style:groove;font-size:x-small;">
	<tr style="background:url('__ROOT__/public/static/images/cartbg.jpg'); text-align:center;font-weight:bold; border-width:1px; border-style:groove;">
		<td>选择</td>
		<td>编号</td>
		<td>商品名称</td>
		<td>市场价</td>
		<td>现价</td>
		<td>数量</td>
		<td>金额</td>
		<td>删除商品</td>
	</tr> 
	<tbody id="goods">
	{assign name="sum" value="0"/}
	{foreach $result as $cart}
	{assign name="sum" value="$sum+$cart.price*$cart.num"/}
	<tr style='text-align:center;height:50px;line-height:50px;'>
		<td><input type='checkbox' name='cartID[]' value='{$cart.cartID}' checked onclick="chk()"></td>
		<td>{$cart.photoID}</td>
		<td>
			<div style='height:50px; float:left;'>
				<img src='__ROOT__/public/static/images/profile_photos/{$cart.picture}' width=48 height=51 border=0>
			</div>
			<div style='height:50px; float:left;'>{$cart.pname}</div>
		</td>
		<td>9999</td>
		<td>{$cart.price}</td>
		<td>
			<input type='text' id='' size='1' value='{$cart.num}' name='num' style='height:20px'>
			<input type='button' onclick='change(this,{$cart.cartID})' value='更新'/>
		</td>
		<td>{$cart.price*$cart.num}</td>
		<td>
			<a href='{:url('cart/deleteCart')}?cartID={$cart.cartID}'>
				<img src='__ROOT__/public/static/images/04shop_deleteID.gif' width='41' height='20' border='0'>
			</a>
		</td>
	</tr>
	{/foreach}
	</tbody>
		<tr>
			<td colspan="6" align="right">总计:￥</td>
			<td id="total" align="right" style="color: red; font-size: 16px; font-bold: true;">{$sum}</td>
			<td>元</td>
		</tr>
	</table>
</form>

<div style="width:881;text-align:center;">
<a href="{:url('index/index')}"><img src="__ROOT__/public/static/images/continue.jpg" border=0></a>&nbsp;
<a href="{:url('cart/clearCart')}"><img src="__ROOT__/public/static/images/clearCart.jpg" border=0></a>&nbsp;
<input type='image' src='__ROOT__/public/static/images/submitOrder.jpg' onclick='javascript:form1.submit()'>
</div>
 </center>
</body>
</html>